package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.TeamMemberItem;
import com.topscore.uke.mvp.contractors.GetTeamStaffListContractor;
import com.topscore.uke.mvp.model.GetTeamStaffListModel;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.utils.UserInfoManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 71468 on 2018/3/30.
 */

public class GetTeamStaffListPresenter implements GetTeamStaffListContractor, GetTeamStaffListContractor.Presenter {
    private View mView;
    private Model mModel;
    private Map<String, Object> mRequest;

    public GetTeamStaffListPresenter(View view) {
        this.mView = view;
        this.mModel = new GetTeamStaffListModel(new CallBack() {
            @Override
            public void onSuccess(BaseResponse<List<TeamMemberItem>> response) {
                mView.onGetDataSuccess(response.getData());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode, errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
    }

    @Override
    public void getStaffList() {
        mRequest = new HashMap<>();
        mRequest.put("userId", UserInfoManager.getUserInfo().getLoginName());
        mModel.getList(mRequest);
    }

    @Override
    public void searchStaffMember(String name) {
        mRequest = new HashMap<>();
        mRequest.put("userId", UserInfoManager.getUserInfo().getLoginName());
        mRequest.put("memberName", name);
        mModel.getList(mRequest);
    }
}
